#include <iostream>
#include <signal.h>
#include <unistd.h>
#include <vector>
#include <sys/types.h>
#include <functional>
#include <cstdio>
#include <sys/wait.h>

// int main()
// {
//     printf("pid is %d\n", getpid());
//     while (1); // 死循环
//     return 0;
// }

int main()
{
    pid_t id = fork();
    if(id == 0)
    {   // child
        sleep(2);
        printf("hello pid\n");
        printf("hello pid\n");
        printf("hello pid\n");
        printf("hello pid\n");
        int a = 10;
        a /= 0;
        // int *p = NULL;
        // *p = 42;
        printf("hello pid\n");
        printf("hello pid\n");
        exit(1);
    }
    int status = 0; 
    waitpid(id, &status,0);
    printf("signal: %d, exit code: %d, core dump: %d\n",
         (status&0x7F), (status>>8)&0xFF, (status>>7)&0x1);
        //  退出信号         退出码         core dump 标志位
    return 0;
}